package com.polaris.live.popup.party

import android.content.Context
import com.blankj.utilcode.util.ActivityUtils
import com.lxj.xpopup.XPopup
import com.lxj.xpopup.core.CenterPopupView
import com.polaris.live.R
import com.polaris.live.common.ext.setOnSingleClickListener
import com.polaris.live.common.mvvm.viewmodel.BaseViewModel
import com.polaris.live.databinding.PopupCustomizedBackgroundBinding
import com.polaris.live.popup.SelectImagePopup
import com.polaris.live.utils.CropUtils

/**
 * 定制背景
 *
 * @author Created by 天晴 on 2024/10/15 19:18
 * @since 1.0.0
 **/
class CustomizedBackgroundPopup(
    context: Context,
    val mViewModel: BaseViewModel,
    val roomId: String,
) : CenterPopupView(context) {

    private lateinit var mBinding: PopupCustomizedBackgroundBinding
    override fun getImplLayoutId(): Int {
        return R.layout.popup_customized_background
    }

    override fun onCreate() {
        super.onCreate()
        mBinding = PopupCustomizedBackgroundBinding.bind(popupImplView)
        mBinding.addRl.setOnSingleClickListener {

            XPopup.Builder(context)
                .moveUpToKeyboard(false)
                .isDestroyOnDismiss(true)
                .asCustom(SelectImagePopup(context, onSelectIt = { type ->
                    val topActivity = ActivityUtils.getTopActivity()
                    when (type) {
                        SelectImagePopup.CAMERA -> {
                            CropUtils.startCamera(topActivity, { result ->

                            }, {})
                        }
                        else -> {
                            CropUtils.startAlbumNoCrop(topActivity, { }, {})
                        }
                    }
                }))
                .show()

        }

    }

    companion object {

        fun show(
            context: Context,
            mViewModel: BaseViewModel,
            roomId: String,
        ) {
            XPopup.Builder(context)
                .isViewMode(false)
                .hasNavigationBar(false)
                .hasShadowBg(true)
                .enableDrag(false)
                .moveUpToKeyboard(false)
                .autoFocusEditText(false)
                .isDestroyOnDismiss(true)
                .asCustom(CustomizedBackgroundPopup(context, mViewModel, roomId))
                .show()
        }
    }
}